package com.reebake.ideal.security.oauth2.config;

import com.reebake.ideal.jdbc.FlywayUtil;
import com.reebake.ideal.security.config.AuthenticationManagerConfig;
import com.reebake.ideal.security.oauth2.mapper.RegisteredClientMapper;
import com.reebake.ideal.security.oauth2.properties.OAuth2ServerProperties;
import org.flywaydb.core.Flyway;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import javax.sql.DataSource;

@Configuration
@EnableConfigurationProperties(OAuth2ServerProperties.class)
@Import({OAuth2AuthorizationServerConfig.class, OAuth2ServerConfig.class, AuthenticationManagerConfig.class})
@AutoConfigureOrder(0)// 要在jwt验证过滤器之前
@MapperScan(basePackageClasses = RegisteredClientMapper.class)
public class OAuth2ServerAutoConfiguration {

    @Bean
    Flyway oauth2ServerFlyway(DataSource dataSource) {
        String schema = "oauth2_server";
        return FlywayUtil.migrate(dataSource, schema);
    }

}
